unit LT_Project;

interface
Uses Windows, SysUtils, PluginElems;
type
  TLT_Project=class
    private
      FUID:TLT_UID;
      FTitle:PWideChar;
      FColor:DWord;
      FGrouped:Boolean;
      FFavorite:Boolean;
      FComment:PWideChar;
      FParentUID:TLT_UID;
      FCreateDate:TDateTime;
    function getTitle: PWideChar;
    procedure setTitle(const Value: PWideChar);
    function getColor: DWord;
    procedure setColor(const Value: DWord);
    function isGrouped: Boolean;
    procedure setGrouped(const Value: Boolean);
    function getFavorite: Boolean;
    procedure setFavorite(const Value: Boolean);
    function getComment: PWideChar;
    procedure setComment(const Value: PWideChar);
    function getParent: TLT_UID;
    procedure setParent(const Value: TLT_UID);
    function getChildsCount: integer;
    function GetCreateDate: TDateTime;

    public
      function isExists():Boolean;
      function getChildUID(number:integer):TLT_UID;
      function Save():TLT_UID;
      function Delete():Boolean;
      constructor Create(uid:TLT_UID);
      property uid:TLT_UID read FUID write FUID;
      property title:PWideChar read getTitle write setTitle;
      property color:DWord read getColor write setColor;
      property createDate:TDateTime read GetCreateDate;
      property grouped:Boolean read isGrouped write setGrouped;
      property favorite:Boolean read getFavorite write setFavorite;
      property comment:PWideChar read getComment write setComment;
      property parentUID:TLT_UID read getParent write setParent;
      property childsCount:integer read getChildsCount;

  end;

implementation

{ TLT_Project }

constructor TLT_Project.Create(uid:TLT_UID);
begin
  FUID:=uid;
  FTitle:='';
  FColor:=0;
  FGrouped:=false;
  FFavorite:=false;
  FComment:='';
  FParentUID:='';
  FCreateDate:=getTime();
end;

function TLT_Project.Delete: Boolean;
begin
  if isExists then
    Result:=AddinLT_Project_Delete(uid)
  else
    Result:=false;
end;

function TLT_Project.getChildsCount: integer;
begin
  if isExists then
    Result:=AddinLT_Project_GetChildsCount(uid)
  else
    Result:=0;
end;

function TLT_Project.getChildUID(number: integer): TLT_UID;
begin
  if isExists then
    Result:=AddinLT_Project_GetChildUID(uid, number)
  else
    Result:=nil;
end;

function TLT_Project.getColor: DWord;
begin
if isExists then
  Result:=AddinLT_Project_GetColor(uid)
else
  Result:=FColor;
end;

function TLT_Project.getComment: PWideChar;
begin
  if isExists then
    Result:=AddinLT_Project_GetCommentText(uid)
  else
    Result:=FComment;
end;

function TLT_Project.GetCreateDate: TDateTime;
begin
  if isExists then
    Result:=AddinLT_Project_GetDateCreate(uid)
  else
    Result:=FCreateDate;
end;

function TLT_Project.getFavorite: Boolean;
begin
  if isExists then
    Result:=AddinLT_Project_IsFavorite(uid)
  else
    Result:=FFavorite;
end;

function TLT_Project.getParent: TLT_UID;
begin
  if isExists then
    Result:=AddinLT_Project_GetParentUID(uid)
  else
    Result:=FParentUID;
end;

function TLT_Project.getTitle: PWideChar;
begin
if isExists then
  Result:=AddinLT_Project_GetTitle(uid)
else
  Result:=FTitle;
end;

function TLT_Project.isExists: Boolean;
begin
  if (uid=nil) and (WideCharToString(uid)='') then
    Result:=false
  else
    Result:=AddinLT_Project_IsPresent(uid);
end;

function TLT_Project.isGrouped: Boolean;
begin
  if isExists then
    Result:=AddinLT_Project_IsGrouped(uid)
  else
    Result:=FGrouped;
end;


function TLT_Project.Save: TLT_UID;
begin
  if isExists then
  begin
    AddinLT_Project_SaveChanges(uid);
  end else
  begin
    FUID:=AddinLT_Project_Insert(uid,parentUID,title,createDate);
    comment:=FComment;
    AddinLT_Project_SaveChanges(uid);
  end;
  Result:=uid;
end;


procedure TLT_Project.setColor(const Value: DWord);
begin

end;

procedure TLT_Project.setComment(const Value: PWideChar);
begin
  if isExists then
    AddinLT_Project_SetCommentText(uid, Value)
  else
    FComment:=Value;
end;


procedure TLT_Project.setFavorite(const Value: Boolean);
begin
  if isExists then
    AddinLT_Project_SetFavorite(uid, value)
  else
    FFavorite:=Value;
end;

procedure TLT_Project.setGrouped(const Value: Boolean);
begin
  if isExists then
    AddinLT_Project_SetGrouped(uid, Value)
  else
    FGrouped:=Value;
end;

procedure TLT_Project.setParent(const Value: TLT_UID);
begin
  if isExists then
    AddinLT_Project_SetParentUID(uid,Value)
  else
    FParentUID:=Value;
end;

procedure TLT_Project.setTitle(const Value: PWideChar);
begin
if isExists then
  AddinLT_Project_SetTitle(uid, Value)
else
  FTitle:=Value;
end;

end.
